﻿(function (S, J) {
    S.namespace("FGT.core", true);
    FGT.core.pageObj = {
        create: function (pageObj) {
            /// <summary>创建类的函数</summary>
            /// <param name="pageObj" type="object">用对象表示的类</param>
            /// <returns type="object">类的实例，已经执行了类的构造函数</returns>
            var args = J.makeArray(arguments);
            args.shift();
            var tempPageObj = function (params) {
                var self = this;
                self.initialize.apply(self, params);
                self.initializeDOM.apply(self, params);
                self.initializeEvent.apply(self, params);
                self.pageLoad.apply(self, params);
            };
            pageObj.initialize = pageObj.initialize || J.noop;
            pageObj.initializeDOM = pageObj.initializeDOM || J.noop;
            pageObj.initializeEvent = pageObj.initializeEvent || J.noop;
            pageObj.pageLoad = pageObj.pageLoad || J.noop;
            pageObj.dispose = pageObj.dispose || J.noop;
            tempPageObj.prototype = pageObj;
            var result = new tempPageObj(args);
            return result;
        }
    };

    FGT.core.constant = {
        jsonResultCode: {
            SUCCESS: 0,
            ERROR: 1
        }
    };

    FGT.core.GetRealLat = function (lat, key) {
        var latOffsetMeters = parseInt((key / 1000));
        var offsetLat = latOffsetMeters / 100000.0;
        return lat - offsetLat;
    };

    FGT.core.GetRealLng = function (lng, key) {
        var lngOffsetMeters = parseInt((key % 1000));
        var offsetLng = lngOffsetMeters / 100000.0;
        return lng - offsetLng;
    };

    FGT.globalObj = {};

    FGT.alert = function (message) {    //统一的提示框
        alert(message);
    }
    S.namespace("func", true);
    S.namespace("FGT.logic.wp", true);
    S.FGT = FGT;

    J.ajaxSetup({
        timeout: 30000,
        datatype: "json"
    });

    S.ajax.setupConfig({
        timeout: 30000,
        dataType: "json"
    });

    //---------------------------jQuery Extentions------------------------------------------------------------------------------

    /// example: "my name is #{name}".template({name:"HuLingfei"}); // output: my name is HuLingfei
    ////////////////////////////////////////// String /////////////////////////////////
    J.extend(String.prototype, {
        template: function (object) {
            var regex = /#{(.*?)}/g;
            return this.replace(regex, function (match, subMatch, index, source) {
                return object[subMatch] || "";
            });
        }
    });

    /// example: "Hello world!".beginWith("Hello"); // output: true
    ////////////////////////////////////////// String /////////////////////////////////
    J.extend(String.prototype, {
        beginWith: function (subStr) {
            if (this.indexOf(subStr) === 0) {
                return true;
            }
            return false;
        }
    });


    /// example: this.jCheckInTime.click(this.onCheckInTimeClick.proxy(this));
    ////////////////////////////////////////// Function /////////////////////////////////
    J.extend(Function.prototype, {
        proxy: function (context) {
            return J.proxy(this, context);
        }
    });

    /// example: this.jCheckInTime.click(this.onCheckInTimeClick.proxy(this));
    ////////////////////////////////////////// Function /////////////////////////////////
    J.extend(Array.prototype, {
        contains: function (item) {
            for (i = 0; i < this.length; ++i) {
                if (this[i] === item) {
                    return true;
                }
            }
            return false;
        }
    });

})(KISSY, jQuery);